package design.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by looper on 2017/8/17.
 */
public class Branch extends Component {
  private List<Component> children = new ArrayList<>();

  public Branch(String name) {
    super(name);
  }

  @Override
  public void Add(Component component) {
    //为分支添加子分支或者子节点
    children.add(component);
  }

  @Override
  public void Rmove(Component component) {
    //为分支删除子分支或子节点
    children.remove(component);
  }

  @Override
  public void Display() {
    System.out.println("枝干: name = "+name);

    for (Component component:children) {
      component.Display();
    }
  }
}
